extends StateBase

@export var timeCircle:float = 2.0
@export var timeShootInterval:float = 0.2
@export var bulletSpeed:float = 100.0
@export var startBulletDir:Vector2 = Vector2.DOWN
@export var isNegtive = false
@export var offsetAngleStartBulletDirPerRound = 10

var timerCircle:float = 0.0
var circleRatio:float = 0.0
var timerShootInterval:float = 0.0

var ownerNode:Boss01


func enter(obj):
	ownerNode = obj
	

func exit(obj):
	reset()
	

func reset():
	timerCircle = 0.0
	timerShootInterval = 0.0
	

func run(delta, obj):
	timerCircle += delta
	circleRatio = timerCircle / timeCircle
	if timerCircle >= timeCircle:
		timerCircle = 0 
		var startBulletDirAngle = Global.vector2Angle(startBulletDir)
		if isNegtive:
			startBulletDirAngle -= offsetAngleStartBulletDirPerRound
		else:
			startBulletDirAngle += offsetAngleStartBulletDirPerRound
		startBulletDir = Global.angle2Vector(startBulletDirAngle)
	
	timerShootInterval += delta
	if timerShootInterval >= timeShootInterval:
		shoot()
		timerShootInterval = 0
		
	
func shoot():
	var bulletInst:Bullet02 = Global.createSceneInst("Bullet02")
	get_tree().current_scene.add_child(bulletInst)
	var startAngle = Global.vector2Angle(startBulletDir)
	if isNegtive:
		startAngle -= (circleRatio * 360.0)
	else:
		startAngle += (circleRatio * 360.0)
	var targetDir = Global.angle2Vector(startAngle)
	bulletInst.setDir(targetDir)
	bulletInst.setSpeed(bulletSpeed)
	bulletInst.setPos(ownerNode.position)
	
	

